package com.deep.test.designpattern.singleton.register;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * <p>Description:注册式单列模式，spring框架用的很多，原理是用cache缓存object，每次从cache中取第一次创建好的对象</p>
 * Created with IDEA
 * author:hudepin
 * createTime:2018/5/17 10:50
 */
public class BeanFactory {
    private BeanFactory(){}
    private static Map<String,Object> iocMaps = new ConcurrentHashMap<String,Object>();
    public Object getBean(String name){
        if(iocMaps.containsKey(name)){
            return iocMaps.containsKey(name);
        }
        try {
            Object obj = Class.forName(name);
            iocMaps.put(name,obj);
            return obj;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}
